"use strict";
const common_vendor = require("../../../common/vendor.js");
const api_community_index = require("../../../api/community/index.js");
const api_user = require("../../../api/user.js");
const stores_userInfo = require("../../../stores/userInfo.js");
if (!Array) {
  const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
  const _easycom_up_form_item2 = common_vendor.resolveComponent("up-form-item");
  const _easycom_up_radio2 = common_vendor.resolveComponent("up-radio");
  const _easycom_up_radio_group2 = common_vendor.resolveComponent("up-radio-group");
  const _easycom_up_form2 = common_vendor.resolveComponent("up-form");
  const _easycom_up_action_sheet2 = common_vendor.resolveComponent("up-action-sheet");
  const _easycom_up_toast2 = common_vendor.resolveComponent("up-toast");
  (_easycom_up_input2 + _easycom_up_form_item2 + _easycom_up_radio2 + _easycom_up_radio_group2 + _easycom_up_form2 + _easycom_up_action_sheet2 + _easycom_up_toast2)();
}
const _easycom_up_input = () => "../../../node-modules/uview-plus/components/u-input/u-input.js";
const _easycom_up_form_item = () => "../../../node-modules/uview-plus/components/u-form-item/u-form-item.js";
const _easycom_up_radio = () => "../../../node-modules/uview-plus/components/u-radio/u-radio.js";
const _easycom_up_radio_group = () => "../../../node-modules/uview-plus/components/u-radio-group/u-radio-group.js";
const _easycom_up_form = () => "../../../node-modules/uview-plus/components/u-form/u-form.js";
const _easycom_up_action_sheet = () => "../../../node-modules/uview-plus/components/u-action-sheet/u-action-sheet.js";
const _easycom_up_toast = () => "../../../node-modules/uview-plus/components/u-toast/u-toast.js";
if (!Math) {
  (_easycom_up_input + _easycom_up_form_item + _easycom_up_radio + _easycom_up_radio_group + _easycom_up_form + _easycom_up_action_sheet + _easycom_up_toast)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "editPersonalInfo",
  setup(__props) {
    const userInfoStore = stores_userInfo.useUserInfoStore();
    const uToastRef = common_vendor.ref(null);
    const uForm = common_vendor.ref(null);
    const data = common_vendor.reactive({
      showCommunity: false,
      communitys: [],
      showStreet: false,
      streets: [],
      showPlot: false,
      plots: [],
      showBuild: false,
      buildings: [],
      form: {
        residenceStatus: userInfoStore.crowdInfo.residenceStatus,
        address: userInfoStore.crowdInfo.address,
        communityId: userInfoStore.crowdInfo.communityId,
        crowdUserId: userInfoStore.crowdInfo.crowdUserId,
        alleyName: userInfoStore.crowdInfo.alleyName,
        alleyId: userInfoStore.crowdInfo.alleyId,
        subdistrict: userInfoStore.crowdInfo.subdistrict,
        subdistrictId: userInfoStore.crowdInfo.subdistrictId,
        building: userInfoStore.crowdInfo.building,
        buildingId: userInfoStore.crowdInfo.buildingId,
        house: userInfoStore.crowdInfo.house,
        phonenumber: userInfoStore.crowdInfo.phonenumber,
        region: userInfoStore.crowdInfo.region,
        street: userInfoStore.crowdInfo.street,
        userName: userInfoStore.crowdInfo.userName,
        idCard: userInfoStore.crowdInfo.idCard,
        communityName: userInfoStore.crowdInfo.communityName,
        vxPhone: userInfoStore.crowdInfo.vxPhone
      },
      rules: {
        communityId: {
          type: "number",
          required: true,
          message: "居住地请选择所属社区",
          trigger: ["blur", "change"]
        },
        subdistrict: {
          type: "string",
          required: true,
          message: "居住地请选择街路巷",
          trigger: ["blur", "change"]
        },
        buildingId: {
          type: "number",
          required: true,
          message: "居住地请选择门楼牌号",
          trigger: ["blur", "change"]
        },
        phonenumber: [
          {
            type: "string",
            required: true,
            message: "请填写手机号码",
            trigger: ["blur", "change"]
          },
          {
            validator: (rule, value, callback) => {
              return common_vendor.index.$u.test.mobile(value);
            },
            message: "手机号码不正确",
            trigger: ["change", "blur"]
          }
        ]
      }
    });
    const {
      showCommunity,
      communitys,
      showStreet,
      streets,
      showPlot,
      plots,
      showBuild,
      buildings,
      form,
      rules
    } = common_vendor.toRefs(data);
    common_vendor.onLoad(() => {
      getCommunityList();
      getAlleyList();
      getPlotList();
      getBuildingList();
    });
    const getCommunityList = () => {
      api_community_index.communityGroup().then((res) => {
        const { data: data2 } = res;
        communitys.value = data2 ?? [];
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const getAlleyList = () => {
      api_community_index.selectAlleyList({ communityId: form.value.communityId }).then((res) => {
        const { data: data2 } = res;
        streets.value = data2 ?? [];
        if (streets.value.length) {
          streets.value = streets.value.map((item) => {
            item.name = item.alleyName;
            return item;
          });
        }
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const getPlotList = () => {
      if (form.value.alleyId) {
        api_community_index.selectSubdistrictList({ alleyId: form.value.alleyId }).then((res) => {
          const { data: data2 } = res;
          plots.value = data2 ?? [];
          if (plots.value.length) {
            plots.value = plots.value.map((item) => {
              item.name = item.subdistrictName;
              return item;
            });
          }
        }).catch((err) => {
          uToastRef.value.show({
            type: "error",
            message: err
          });
        });
      }
    };
    const getBuildingList = () => {
      api_community_index.selectBuildingList({
        alleyId: form.value.alleyId,
        subId: form.value.subdistrictId ? form.value.subdistrictId : ""
      }).then((res) => {
        const { data: data2 } = res;
        buildings.value = data2 ?? [];
        if (buildings.value.length) {
          buildings.value = buildings.value.map((item) => {
            item.name = item.buildingName;
            return item;
          });
        }
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const communitySelect = (e) => {
      form.value.communityName = e.name;
      form.value.communityId = e.id;
      resetData(1);
      getAlleyList();
    };
    const streetSelect = (e) => {
      form.value.alleyName = e.name;
      form.value.alleyId = e.id;
      resetData(2);
      getPlotList();
      getBuildingList();
    };
    const plotSelect = (e) => {
      form.value.subdistrict = e.name;
      form.value.subdistrictId = e.id;
      resetData(3);
      getBuildingList();
    };
    const buildSelect = (e) => {
      form.value.building = e.name;
      form.value.buildingId = e.id;
    };
    const resetData = (type) => {
      if (type <= 1) {
        form.value.alleyName = "";
        form.value.alleyId = "";
      }
      if (type <= 2) {
        form.value.subdistrict = "";
        form.value.subdistrictId = "";
      }
      if (type <= 3) {
        form.value.building = "";
        form.value.buildingId = "";
      }
    };
    const onsubmit = () => {
      uForm.value.validate().then((res) => {
        common_vendor.index.showLoading({
          title: "提交中",
          mask: true
        });
        api_user.updateCrowdUser(form.value).then((res2) => {
          common_vendor.index.hideLoading();
          uToastRef.value.show({
            type: "success",
            message: "修改成功"
          });
          getCrowdUserInfo();
          let timer = setTimeout(() => {
            common_vendor.index.navigateBack({
              delta: 1
            });
            clearTimeout(timer);
          }, 1500);
        }).catch((err) => {
          common_vendor.index.hideLoading();
          uToastRef.value.show({
            type: "error",
            message: err
          });
        });
      }).catch(() => {
      });
    };
    const getCrowdUserInfo = () => {
      api_user.crowdUserInfo({ crowdUserId: userInfoStore.userInfo.userId }).then((res) => {
        const { data: data2 } = res;
        userInfoStore.setCrowdInfo(data2);
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    common_vendor.onReady(() => {
      uForm.value.setRules(rules.value);
    });
    return (_ctx, _cache) => {
      return {
        a: common_vendor.o(($event) => common_vendor.unref(form).vxPhone = $event),
        b: common_vendor.p({
          border: "none",
          color: "#707070",
          inputAlign: "right",
          disabled: true,
          modelValue: common_vendor.unref(form).vxPhone
        }),
        c: common_vendor.p({
          label: "账号",
          borderBottom: true
        }),
        d: common_vendor.p({
          activeColor: "#0189FE",
          name: 0,
          label: "常住"
        }),
        e: common_vendor.p({
          activeColor: "#0189FE",
          name: 1,
          label: "暂住"
        }),
        f: common_vendor.o(($event) => common_vendor.unref(form).residenceStatus = $event),
        g: common_vendor.p({
          placement: "row",
          modelValue: common_vendor.unref(form).residenceStatus
        }),
        h: common_vendor.p({
          label: "类型",
          prop: "residenceStatus",
          borderBottom: true
        }),
        i: common_vendor.o(($event) => common_vendor.unref(form).userName = $event),
        j: common_vendor.p({
          border: "none",
          color: "#707070",
          inputAlign: "right",
          disabled: true,
          modelValue: common_vendor.unref(form).userName
        }),
        k: common_vendor.p({
          label: "姓名",
          prop: "userName",
          borderBottom: true
        }),
        l: common_vendor.o(($event) => common_vendor.unref(form).idCard = $event),
        m: common_vendor.p({
          border: "none",
          color: "#707070",
          inputAlign: "right",
          disabled: true,
          modelValue: common_vendor.unref(form).idCard
        }),
        n: common_vendor.p({
          label: "身份证号",
          prop: "idCard",
          borderBottom: true
        }),
        o: common_vendor.o(($event) => common_vendor.unref(form).phonenumber = $event),
        p: common_vendor.p({
          border: "none",
          color: "#000000",
          inputAlign: "right",
          placeholderStyle: "{color: '#707070'}",
          clearable: true,
          modelValue: common_vendor.unref(form).phonenumber
        }),
        q: common_vendor.p({
          label: "联系电话",
          prop: "phonenumber",
          borderBottom: true
        }),
        r: common_vendor.o(($event) => common_vendor.unref(form).region = $event),
        s: common_vendor.p({
          border: "none",
          color: "#707070",
          disabled: true,
          modelValue: common_vendor.unref(form).region
        }),
        t: common_vendor.o(($event) => common_vendor.unref(form).street = $event),
        v: common_vendor.p({
          border: "none",
          color: "#707070",
          disabled: true,
          modelValue: common_vendor.unref(form).street
        }),
        w: common_vendor.o(($event) => common_vendor.unref(form).communityName = $event),
        x: common_vendor.p({
          placeholder: "社区名称",
          border: "none",
          disabled: true,
          disabledColor: "#ffffff",
          placeholderStyle: "{color: '#707070'}",
          suffixIcon: "arrow-down",
          suffixIconStyle: {
            color: "#777777",
            fontSize: "20rpx"
          },
          modelValue: common_vendor.unref(form).communityName
        }),
        y: common_vendor.o(($event) => showCommunity.value = true),
        z: common_vendor.p({
          label: "居住地：",
          prop: "communityId"
        }),
        A: common_vendor.o(($event) => common_vendor.unref(form).alleyName = $event),
        B: common_vendor.p({
          placeholder: "街路巷",
          border: "none",
          disabled: true,
          disabledColor: "#ffffff",
          placeholderStyle: "{color: '#707070'}",
          suffixIcon: "arrow-down",
          suffixIconStyle: {
            color: "#777777",
            fontSize: "20rpx"
          },
          modelValue: common_vendor.unref(form).alleyName
        }),
        C: common_vendor.o(($event) => showStreet.value = true),
        D: common_vendor.o(($event) => common_vendor.unref(form).building = $event),
        E: common_vendor.p({
          placeholder: "门楼牌号",
          border: "none",
          disabled: true,
          disabledColor: "#ffffff",
          placeholderStyle: "{color: '#707070'}",
          suffixIcon: "arrow-down",
          suffixIconStyle: {
            color: "#777777",
            fontSize: "20rpx"
          },
          modelValue: common_vendor.unref(form).building
        }),
        F: common_vendor.o(($event) => showBuild.value = true),
        G: common_vendor.p({
          label: "",
          prop: "buildingId"
        }),
        H: common_vendor.o(($event) => common_vendor.unref(form).house = $event),
        I: common_vendor.p({
          border: "none",
          color: "#000000",
          placeholder: "输入户号 例如:1-1",
          placeholderStyle: "{color: '#707070'}",
          clearable: true,
          modelValue: common_vendor.unref(form).house
        }),
        J: common_vendor.p({
          label: "    ",
          labelWidth: "0"
        }),
        K: common_vendor.sr(uForm, "78ba9ab3-0", {
          "k": "uForm"
        }),
        L: common_vendor.p({
          labelPosition: "left",
          model: common_vendor.unref(form),
          rules: common_vendor.unref(rules),
          labelWidth: "75"
        }),
        M: common_vendor.o(($event) => showCommunity.value = false),
        N: common_vendor.o(communitySelect),
        O: common_vendor.p({
          show: common_vendor.unref(showCommunity),
          actions: common_vendor.unref(communitys),
          title: "请选择社区"
        }),
        P: common_vendor.o(($event) => showStreet.value = false),
        Q: common_vendor.o(streetSelect),
        R: common_vendor.p({
          show: common_vendor.unref(showStreet),
          actions: common_vendor.unref(streets),
          title: "请选择街路巷"
        }),
        S: common_vendor.o(($event) => showPlot.value = false),
        T: common_vendor.o(plotSelect),
        U: common_vendor.p({
          show: common_vendor.unref(showPlot),
          actions: common_vendor.unref(plots),
          title: "请选择小区"
        }),
        V: common_vendor.o(($event) => showBuild.value = false),
        W: common_vendor.o(buildSelect),
        X: common_vendor.p({
          show: common_vendor.unref(showBuild),
          actions: common_vendor.unref(buildings),
          title: "请选择门楼牌号"
        }),
        Y: common_vendor.o(onsubmit),
        Z: common_vendor.sr(uToastRef, "78ba9ab3-26", {
          "k": "uToastRef"
        })
      };
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-78ba9ab3"]]);
wx.createPage(MiniProgramPage);
